package com.platform.common.utils;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
import com.tencentcloudapi.faceid.v20180301.models.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 人脸核身SaaS增强版本
 */
@Slf4j
@Component
public class GetDetectInfoEnhanced {
    /**
     * 发起人脸活体认证
     * @param SecretId
     * @param SecretKey
     * @return
     * @throws TencentCloudSDKException
     */
    public static DetectAuthResponse detectAuth(String SecretId,String SecretKey,String ruleId,String idCard,String name,String redirectUrl) throws TencentCloudSDKException {
        Credential cred = new Credential(SecretId,SecretKey);
        // 实例化一个http选项，可选的，没有特殊需求可以跳过
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint("faceid.tencentcloudapi.com");
        // 实例化一个client选项，可选的，没有特殊需求可以跳过
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        // 实例化要请求产品的client对象,clientProfile是可选的
        FaceidClient client = new FaceidClient(cred, "ap-guangzhou", clientProfile);
        // 实例化一个请求对象,每个接口都会对应一个request对象
        DetectAuthRequest req = new DetectAuthRequest();
        req.setIdCard(idCard);
        req.setName(name);
        req.setRedirectUrl(redirectUrl);
        req.setRuleId(ruleId);
        // 返回的resp是一个DetectAuthResponse的实例，与请求对象对应
        DetectAuthResponse resp = client.DetectAuth(req);
        // 输出json格式的字符串回包
//        System.out.println(DetectAuthResponse.toJsonString(resp));
        log.info(DetectAuthResponse.toJsonString(resp));
        return resp;
    }

    /**
     * 获取结果
     * @return
     * @throws TencentCloudSDKException
     */
    public static GetDetectInfoEnhancedResponse getDetectInfoEnhanced(String SecretId,String SecretKey,String ruleId,String BizToken) throws TencentCloudSDKException {

        Credential cred = new Credential(SecretId, SecretKey);
        // 实例化一个http选项，可选的，没有特殊需求可以跳过
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint("faceid.tencentcloudapi.com");

        // 实例化一个client选项，可选的，没有特殊需求可以跳过
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        // 实例化要请求产品的client对象,clientProfile是可选的
        FaceidClient client = new FaceidClient(cred, "", clientProfile);
        // 实例化一个请求对象,每个接口都会对应一个request对象
        GetDetectInfoEnhancedRequest req = new GetDetectInfoEnhancedRequest();
        req.setRuleId(ruleId);
        req.setBizToken(BizToken);
        // 返回的resp是一个GetDetectInfoEnhancedResponse的实例，与请求对象对应
        GetDetectInfoEnhancedResponse resp = client.GetDetectInfoEnhanced(req);
        // 输出json格式的字符串回包
//        System.out.println(GetDetectInfoEnhancedResponse.toJsonString(resp));
        return resp;
    }


}
